package com.cn.jinhao.hotline.provider.huawu.config;

import com.google.common.base.Predicates;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

/**
 * hotline-spring-cloud
 * <p>Description: Swagger2相关信息配置</p>
 *
 * @author ShaneMew
 * @version 1.0
 * @date 2019/12/23
 * @since 2019-12-23
 */

@EnableSwagger2
@Configuration
public class SwaggerConfig {
    @Value("${swagger.enabled}")
    private Boolean enabled;

    @Bean
    public Docket createRestApi() {
        return new Docket(DocumentationType.SWAGGER_2)
            .enable(enabled)
            .apiInfo(apiInfo())
            .select()
            .paths(Predicates.not(PathSelectors.regex("/error.*")))
            .paths(Predicates.not(PathSelectors.regex("/actuator.*")))
            .build();
    }

    private ApiInfo apiInfo() {
        return new ApiInfoBuilder()
            .title("HotLine的API文档")
            .license("JinHao Corp.")
            .description("This is APIs Document for the HotLine Software System.")
            .contact(new Contact("", "", "shaneroy@yeah.net"))
            .termsOfServiceUrl("")
            .version("1.0")
            .build();
    }
}
